<template>
  <view>
	
  
<view class="cu-card case isCard" v-if="congnumbershow==false">
      <view class="cu-item shadow">
        <view class="image">
          <image :src="orderinfo.main_walletaddress_qrcode" mode="widthFix"></image>
		  <view class="u-text-center">{{ auto_discover_status }}</view>
        </view>
        <view class="cu-list padding">
          <view>请在30分钟内转帐到此钱包</view>
				<view class="cu-item">充值:{{ orderinfo.packagevalue }}USD
				  请往此 USDT 充入{{ orderinfo.totalamount }}
					{{ orderinfo.unit }}(!!到账金额需要与下方显示的金额一致，否则系统不到账!!)
				</view>
				<view class="cu-item">
					<view class="content flex-sub">
					  <view class="text-grey">钱包地址：{{ orderinfo.main_walletaddress }}</view>
					</view>
				</view>
        </view>
      </view>

    <view class="flex flex-direction padding" v-show="orderinfo.status != 1">
      <button class="cu-btn bg-blue margin-tb-sm lg" @tap="dodel()">
        取消本次充币
      </button>
    </view>
    <view class="padding-sm" v-show="orderinfo.status == 1">
      <view class="bg-gradual-blue padding radius text-center shadow-blur">
        <view class="text-lg">OK</view>
        <view class="margin-top-sm text-Abc">本次交易已完成</view>
      </view>
    </view> 
</view>
	
				<u-popup v-model="congnumbershow" mode="bottom" border-radius="14" :mask-close-able="false" :closeable="true" @close="back()">
				<view class="pops u-padding-20">
					<u-form ref="uForm">
						<u-form-item class="form-item" label="Available balance" label-position="top" label-width="220">
						  <u-input placeholder="请输入要充入的数量" v-model="packagevalue" type="text"/>
						  <text slot="right" style="font-size: 22rpx">USD</text>
						</u-form-item>
					</u-form>
					<u-gap height="40"></u-gap>
					<u-button type="primary" @click="getorder">Submit</u-button>
				</view>
				</u-popup>


  </view>
</template>

<script>
import { mapState, mapMutations } from "vuex";
export default {
  data() {
    return {
      orderinfo: {},
      delcoinid: "",
	  congnumbershow:false,
	  packagevalue:'',
	  auto_discover_status:'',
	  code:''
    };
  },
  async onLoad(options) {
    // const userinfo = uni.getStorageSync("userInfo");
    // if (userinfo && userinfo.token) {
    //   this.login(userinfo);
    //   this.$store.dispatch("resetuserinfo");
    // }
    // this.delcoinid = options.coinorderid;
    // this.app.get({
    //   url: this.serverAddress + "/index.php?m=vueapi&c=wallet&a=getcoinorder",
    //   method: "GET",
    //   data: {
    //     uid: this.userInfo.users_id,
    //     token: this.userInfo.token,
    //     orderid: options.coinorderid,
    //   },
    //   success: (res) => {
    //     this.orderinfo = res.order;
    //     console.log(this.orderinfo);
    //   },
    //   errmsg: (res) => {},
    // });

    //this.shouinfo=this.userInfo.balance[options.coinid];
    //console.log(this.shouinfo)
	this.getorder()
  },
  computed: {
    ...mapState(["user"]),
  },
  methods: {
	  back(){
		  if (this.code==202){
			  uni.navigateBack(1);
		  }
		  
	  },
	getorder(){
        this.$api("assets.buycoinorder", {
			coinid:1,
			packagevalue:this.packagevalue
		}).then((res) => {
			console.log(res)
			this.code=res.data.code
            if (res.data.code==202){
				console.log('202')
				this.congnumbershow=true
			}else if(res.data.code==200){
				this.congnumbershow=false
				this.orderinfo=res.data
			}
			this.autodiscover();
        }).catch((e) => {});
	},
    autodiscover(wallet) {

      this.auto_discover_status = "充值检测中...";
      this.$api("assets.autodiscover", {
        walletaddress: '',
      }).then((res) => {
          console.log(res);
          if (res.code == 200) {
            this.auto_discover_status = res.data.msg;
			if (res.data.code==200){
				this.$Router.push({path:"/pages/componentsA/my/success",query:{title: '充值成功',msg:res.data.msg}});
			}
          } else {
            this.auto_discover_status = "";
          }
        }).catch((e) => {});
    },
    dodel() {
      this.app.get({
        url: this.serverAddress + "/index.php?m=vueapi&c=wallet&a=delcoinorder",
        method: "GET",
        data: {
          uid: this.userInfo.users_id,
          token: this.userInfo.token,
          orderid: this.delcoinid,
        },
        success: (res) => {
          this.$api.msg(res.msg);
          this.app.navTo("/pages/componentsA/assets/details", {
            coinid: this.orderinfo.cointype,
          });
        },
        errmsg: (res) => {},
      });
    },
  },
};
</script>
<style lang="scss">
	.pops {
	  background: #ffffff;
	  height: 900rpx;
	  .title {
	    background: #eeeeee;
	    padding: 20rpx 30rpx;
	  }
	}
</style>
